/**
 * @filename:UserCardServiceImpl 2019-01-17 14:56:43
 * @project skz  V1.3.3
 * Copyright(c) 2018 Liu,Wenzhao Co. Ltd. 
 * All right reserved. 
 */
package com.bingsum.service;

import com.bingsum.annotation.Api;
import com.bingsum.model.User;
import com.bingsum.util.ApiUtil;
import com.bingsum.util.ParaData;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import com.bingsum.model.UserCard;
import com.bingsum.mapper.UserCardMapper;

/**   
 *  
 * @Description:  [用户身份信息]——SERVICE
 * @Author:       Liu,Wenzhao   
 * @CreateDate:   2019-01-17 14:56:43
 * @Version:      V1.3.3
 *    
 */
@Service("userCardService")
@Transactional(readOnly = true)
public class UserCardService{

    @Autowired
    private UserCardMapper userCardMapper;
    @Autowired
    private UserService userService;

    @Api
    public Object getUserCardInfoList(ParaData pd) {
        Page<?> page = PageHelper.startPage(pd.getInteger("currentPage"), 20);
        userCardMapper.getUserCardInfoList(pd);
        return ApiUtil.returnObject(pd, page);
    }

    @Api
    public List<ParaData> getNameByOid(ParaData pd) {
        return userCardMapper.getNameByOid(pd);
    }

    @Api
    @Transactional(readOnly = false)
    public Object newUserCardInfo(ParaData pd) {
        UserCard userCard = pd.toBean(UserCard.class);
        User user =this.userService.findByOpenId(pd.getString("openId"));
        userCard.setUserId(user.getId());
        this.userCardMapper.insert(userCard);
        System.out.println(userCard.toString());
        return ApiUtil.returnOK(pd,userCard);
    }

    @Api
    @Transactional(readOnly = false)
    public Object setUserCardInfo(ParaData pd) {
//        UserCard userCard = pd.toBean(UserCard.class);
        UserCard userCard = pd.toUpdateBean(UserCard.class);
        this.userCardMapper.updateByPrimaryKeySelective(userCard);
        return ApiUtil.returnOK(pd,userCard);
    }

    @Api
    @Transactional(readOnly = false)
    public Object delUserCard(ParaData pd) {
        UserCard userCard = pd.toDeleteBean(UserCard.class);
        userCardMapper.delUserCard(pd);
        return ApiUtil.returnOK(pd,userCard.getId());
    }



}